__author__ = 'Berendeeva'

import unittest

from setting.service import Session, Login, Movie
from tests import URL, USERNAME, PASSWORD
from tests.movie import MOVIE_TITLE, MOVIE_YEAR, MOVIE_ADDITIONAL_DESCRIPTION


class MovieTest(unittest.TestCase):

    def test_add_movie_with_filling_required_fields(self):
        """
        Implements login in Firefox.
        """
        driver = Session().open_firefox()
        Login(driver=driver, url=URL).login(username=USERNAME, password=PASSWORD)
        Movie(driver=driver).add_movie(title=MOVIE_TITLE, year=MOVIE_YEAR)
        Session().close_browser(driver)

    def test_add_movie_with_filling_all_fields(self):
        """
        Implements adding a movie with filling all fields.
        """
        driver = Session().open_firefox()
        Login(driver=driver, url=URL).login(username=USERNAME, password=PASSWORD)
        Movie(driver=driver).add_movie(title=MOVIE_TITLE, year=MOVIE_YEAR, **MOVIE_ADDITIONAL_DESCRIPTION)
        Session().close_browser(driver)

    def test_delete_movie(self):
        """
        Implements deletion of a movie.
        """
        driver = Session().open_firefox()
        Login(driver=driver, url=URL).login(username=USERNAME, password=PASSWORD)
        Movie(driver=driver).delete_movie()
        Session().close_browser(driver)

    def test_check_test_without_filling_year(self):
        """
        Implements check of text, when user forgets to fill year field.
        """
        driver = Session().open_firefox()
        Login(driver=driver, url=URL).login(username=USERNAME, password=PASSWORD)
        Movie(driver=driver).check_text_without_filling_required_fields(title=MOVIE_TITLE)
        Session().close_browser(driver)

    def test_check_test_without_filling_title(self):
        """
        Implements check of text, when user forgets to fill title field.
        """
        driver = Session().open_firefox()
        Login(driver=driver, url=URL).login(username=USERNAME, password=PASSWORD)
        Movie(driver=driver).check_text_without_filling_required_fields(year=MOVIE_YEAR)
        Session().close_browser(driver)

    def test_check_test_without_filling_required_fieds(self):
        """
        Implements check of text, when user forgets to fill all required fields.
        """
        driver = Session().open_firefox()
        Login(driver=driver, url=URL).login(username=USERNAME, password=PASSWORD)
        Movie(driver=driver).check_text_without_filling_required_fields()
        Session().close_browser(driver)

    def test_search_existent_movie(self):
        """
        Implements search for movies by keyword and gets a results.
        """
        self.test_add_movie_with_filling_required_fields()
        driver = Session().open_firefox()
        Login(driver=driver, url=URL).login(username=USERNAME, password=PASSWORD)
        Movie(driver=driver).find_movie(keyword=MOVIE_TITLE)
        Session().close_browser(driver)

    def test_search_not_existent_movie(self):
        """
        Implements search for movies by keyword and gets nothing.
        """
        driver = Session().open_firefox()
        Login(driver=driver, url=URL).login(username=USERNAME, password=PASSWORD)
        Movie(driver=driver).find_movie(keyword='abracadabra')
        Session().close_browser(driver)

if __name__ == "__main__":
    unittest.main()
